<?php include 'header.php'; 
include 'connect.php';

if ( isset($_POST['mail']) && $_POST['mail'] != "" )
{
	$sql = "SELECT user_id FROM $table_name 
		  WHERE email='$_POST[mail]'";
	$result = mysql_query($sql,$db) or die("erreur 1: ".mysql_error()); 
	$check = mysql_fetch_row($result);
	if ( $check > 0 )
	{
		$sql = "SELECT * FROM $table_name 
		  WHERE email='$_POST[mail]'";
		$result = mysql_query($sql,$db) or die("erreur 2: ".mysql_error()); 
		
		function make_seed()
		{
		  list($usec, $sec) = explode(' ', microtime());
		  return (float) $sec + ((float) $usec * 100000);
		}
		srand(make_seed());
		$randval = rand(10000000000,99999999999);


		$id = mysql_fetch_object($result);
		
		$sql = ("INSERT INTO ".$table_backup." VALUES(
			'', 
			'".mysql_real_escape_string($id->user_id)."', 
			'".mysql_real_escape_string($randval)."'
			)");
		mysql_query($sql) or die('Ajout du code impossible'.mysql_error());
		$message = '
			<html>

			<head>
				   <title>New Password on '.$_GLOBALS[site_name].'</title>
			</head>
			<body>
				   <p>If you asked for a new password, click this link or go to <a href="'.$_GLOBALS['site_url'].'recover_password.php?code='.$randval.'&mail='.$id->email.'">this page</a> and 
				   enter your mail and the code: '.$randval.'.
				   </p>
				   <p>If you don\'t, please just ignore this mail</p>
			 </body>
			 </html>
			 ';
		$headers  = 'MIME-Version: 1.0' . "\r\n";
			 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		//mail($id->email, 'New Password Confirmation', $message);
		$msgsend = "<p class=\"ident_info\" >An email has been sent to you for verification. Please, go to your inbox and follow the insctructions.</p>";
	}
	else
	{
		$msgsend = "<p class=\"alert_error\" >The mail you provided isn't in our database. If you don't already have an account, feel free to <a href=\"".$_GLOBALS['site_url']."register.php\">register</a>.</p>";
	}
}

?>

	  <div id="teaser">
	  </div>


	  <div id="main">


			<div id="gauche">
				<div class="nothing">
					<?php include 'sidebar.php'; ?>
				</div>
			</div>

			<div id="droite">
			
				<div class="bgwhite bdg topbdg">	
					<div class="subcolumns">
						<div class="c33l">
							<div class="subcl">
								<div class="ylert">
									<p>If you have lost your password, type your email in the form. 
									We will send you a mail with the process to generate a new password.</p>
								</div>
							</div>
						</div>


						<div class="c66r">
							<div class="subcr">
								<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>" id="newpwd" name="newpwd">
									<label for="mail">Email:</label>
									<input id="mail" type="text" name="mail" value="" />
									<input type="submit" name="send" value="Send" />
								</form>
								<?php if ( isset($msgsend) ) echo $msgsend; ?>
							</div>
						</div>
					</div>
				</div>
			
				<div class="nothing">
					<div class="bgwhite bdg topbdg">		
						<div class="subcolumns">
							<div class="c50l">
								<div class="subcl">
								<div class="floatbox justify"><img src="<?php echo $_GLOBALS['site_url']; ?>/img/pic_index.png" style="float:left;" alt="pic_index" />
								<h5>Bienvenue sur OpenCV !</h5>
								<p> Envie de pouvoir facilement g&eacute;rer votre CV? De pouvoir facilement le t&eacute;l&eacute;charger dans plusieurs formats?</p>
								<p> Vous &ecirc;tes au bon endroit! Inscrivez-vous en quelques clics et commencez &agrave; utiliser nos services gratuitement!</p>
								</div>
								</div>
							</div>

							<div class="c50r">
								<div class="subcr">
									<?php
								require_once('php/simplepie.inc');
								$feed = new SimplePie('http://feeds.feedburner.com/Opencv');
								$feed->handle_content_type();
								?>
									<h5>Sur le blog OpenCV Manager</h5>
									<?php
									$i = 0;
									foreach ($feed->get_items() as $item):

									?>
									<p class="title"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a>

									<small>- <?php echo $item->get_date('j F Y | g:i a'); ?></small>
									</p>
									<p><?php echo $item->get_description(); ?></p>


									<?php 
									$i++;
									if ( $i == 1 )
									{
										break;
									}

									endforeach; ?>
								</div>
							</div>
						</div>
					</div>

				</div>
			</div>
			</div>


<?php include 'footer.php'; ?>			


